<table id="admin_checkInfo" data-options="fit:true"></table>
<script>
$(function(){
	$('#admin_checkInfo').datagrid({
		url:'../checkInfo/selectCheckInfo',
		loadMsg:'数据加载中...',
		fitColumns:true,
		rownumbers:true,
		striped:true,
		sortName:'cid',
		sortOrder:'asc',
		remoteSort:false,
		columns:[[
			{field:'cids',title:'',width:100,align:'center',checkbox:true},
			{field:'cid',title:'巡检编号',width:50,align:'center',sortable:true},
			{field:'ctime',title:'开始时间',width:100,align:'center'}, 
			{field:'etime',title:'结束时间',width:100,align:'center'}, 
			{field:'ccontent',title:'巡检重点',width:300,align:'center'}
		]],
		toolbar: [{
			iconCls: 'icon-add',
			text:'创建',
			handler: function(){
				$("#add_checkInfo").dialog("open");
			}
		},'-',{
			iconCls: 'icon-remove',
			text:'删除',
			handler: function(){
				var cids=$('#admin_checkInfo').datagrid('getSelections');
				if(cids.length==0){
					$.messager.alert('错误提示','请选择删除项!','error');
					return;
				}
				if(cids.length>1){
					$.messager.alert('错误提示','事关重大,请逐项选择!','error');
					$('#admin_checkInfo').datagrid('clearSelections');
				}else{
					var cid=cids[0].cid;
					$.ajax({
					    url: "../checkInfo/delCheckInfo",    //请求的url地址
					    dataType: "json",   //返回格式为json
					    async: true, //请求是否异步，默认为异步，这也是ajax重要特性
					    type: "POST", 
					    data: { "cid": cid},    //参数值
					    success: function(data) {
					    	if(parseInt($.trim(data.obj))>=1){
					    		$.messager.show({
									title:'成功提示',
									msg:'删除信息成功！',
									timeout:3000,
									showType:'slide'
								});
								$('#admin_checkInfo').datagrid("reload");
					    	}else{
					    		$.messager.alert('错误提示','网络错误,请稍后重试!','error');
					    	}
					    },
					});
				}
			}
		}]

	});
});

function add_checkInfo(){
	var  ctime= $('#admin_ctime').datebox('getValue');
	var  etime= $('#admin_etime').datebox('getValue');
	var  ccontent=$("#admin_ccontent").val();
	if(ctime!="" && etime!="" && ccontent!=""){
		$.ajax({
		    url: "../checkInfo/addCheckInfo",    //请求的url地址
		    dataType: "json",   //返回格式为json
		    async: true, //请求是否异步，默认为异步，这也是ajax重要特性
		    type: "POST", 
		    data: { "ctime": ctime,"etime":etime,"ccontent":ccontent },    //参数值
		    success: function(data) {
		    	if(parseInt($.trim(data.obj))>=1){
		    		$.messager.show({
						title:'成功提示',
						msg:'创建巡检成功！',
						timeout:3000,
						showType:'slide'
					});
		    		$('#ctime').datebox('setValue', '');	// 设置datebox 值
		    		$('#etime').datebox('setValue', '');
		    		$("#admin_ccontent").val('');
		    		$("#add_checkInfo").dialog("close");
					$('#admin_checkInfo').datagrid("reload");
		    	}else{
		    		$.messager.alert('错误提示','网络错误,请稍后重试!','error');
		    	}
		    },
		});
	}
}
</script>
<div id="add_checkInfo" class="easyui-dialog" title="创建巡检任务" style="width:400px;height:330px;"
	data-options="iconCls:'icon-add',resizable:true,modal:true,closed:true">
	<p style="width:100%;text-align:center;">
		<br /> <br /> 
		<label>开始时间：</label><input id="admin_ctime" name="ctime" type="text" class="easyui-datebox" required="required"></input>
		<br /> <br /> 
		<label>结束时间：</label><input id="admin_etime" name="etime" type="text" class="easyui-datebox" required="required"></input>
		<br /> <br />
		&nbsp;&nbsp;&nbsp;&nbsp;<label style="vertical-align: top;">巡检内容：</label><textarea rows="4" cols="20" id="admin_ccontent" name="ccontent" style="resize:none;" maxlength="50"></textarea>
		<br /> <br /> 
		<input type="button" value="创建" style="width:80px;" onclick="add_checkInfo()"/>
	</p>
</div>
